package n_swing_jtable;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableRowSorter;

public class JTableEx2 extends JInternalFrame {

	private static final long serialVersionUID = 1L;

	public  JTextField irum = null;
	public  JTextField address = null;
	public JTextField phone = null;
	public JTable table = null;

	
	private JPanel jContentPane = null;
	private JPanel inputPanel = null;
	private JPanel controlPanel = null;
	private JLabel jLabel = null;
	private JLabel jLabel1 = null;

	private JLabel jLabel2 = null;

	private JLabel jLabel3 = null;


	private JLabel jLabel4 = null;


	private JButton appendBtn = null;

	private JButton deleteBtn = null;

	private JButton printBtn = null;

	private JScrollPane scroll = null;


	DefaultTableModel model;
	TableEventListener2 event2;

	/**
	 * This method initializes inputPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getInputPanel() {
		if (inputPanel == null) {
			jLabel4 = new JLabel();
			jLabel4.setText("연락처");
			jLabel3 = new JLabel();
			jLabel3.setText("주소");
			jLabel2 = new JLabel();
			jLabel2.setText("성명");
			jLabel1 = new JLabel();
			jLabel1.setText("");
			jLabel = new JLabel();
			jLabel.setText("회원입력");
			GridLayout gridLayout = new GridLayout(4, 2);
			inputPanel = new JPanel();
			inputPanel.setLayout(gridLayout);
			inputPanel.add(jLabel1, null);
			inputPanel.add(jLabel, null);
			inputPanel.add(jLabel2, null);
			inputPanel.add(getIrum(), null);
			inputPanel.add(jLabel3, null);
			inputPanel.add(getAddress(), null);
			inputPanel.add(jLabel4, null);
			inputPanel.add(getPhone(), null);
		}
		return inputPanel;
	}

	/**
	 * This method initializes controlPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getControlPanel() {
		if (controlPanel == null) {
			GridLayout gridLayout1 = new GridLayout(1, 3);
			gridLayout1.setRows(1);
			controlPanel = new JPanel();
			controlPanel.setLayout(gridLayout1);
			controlPanel.add(getAppendBtn(), null);
			controlPanel.add(getDeleteBtn(), null);
			controlPanel.add(getPrintBtn(), null);
		}
		return controlPanel;
	}

	/**
	 * This method initializes irum
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getIrum() {
		if (irum == null) {
			irum = new JTextField();
		}
		return irum;
	}

	/**
	 * This method initializes address
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getAddress() {
		if (address == null) {
			address = new JTextField();
		}
		return address;
	}

	/**
	 * This method initializes phone
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getPhone() {
		if (phone == null) {
			phone = new JTextField();
		}
		return phone;
	}

	/**
	 * This method initializes appendBtn
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getAppendBtn() {
		if (appendBtn == null) {
			appendBtn = new JButton("Append");
		}
		return appendBtn;
	}

	/**
	 * This method initializes deleteBtn
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getDeleteBtn() {
		if (deleteBtn == null) {
			deleteBtn = new JButton("Delete");
		}
		return deleteBtn;
	}

	/**
	 * This method initializes printBtn
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getPrintBtn() {
		if (printBtn == null) {
			printBtn = new JButton("Print");
		}
		return printBtn;
	}

	/**
	 * This method initializes scroll
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getScroll() {
		if (scroll == null) {
			scroll = new JScrollPane();
			scroll.setViewportView(getTable());
		}
		return scroll;
	}

	/**
	 * This method initializes table
	 * 
	 * @return javax.swing.JTable
	 */
	private JTable getTable() {
		if (table == null) {
			String[] header = { "성명", "주소", "연락처" };
			model = new DefaultTableModel(header, 0);
			table = new JTable(model);
			table.setRowSorter(new TableRowSorter<>(model));

			TableColumnModel tModel = table.getColumnModel();
			tModel.getColumn(1).setPreferredWidth(200);
		}
		return table;
	}

	/**
	 * This is the default constructor
	 */
	public JTableEx2() {
		super("DefaultTableModel 1", true, true, true, false);
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(438, 147);
		this.setContentPane(getJContentPane());
		this.setTitle("JTableTest2");
		this.setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE);
//		event2 = new TableEventListener2(table, appendBtn, deleteBtn, printBtn);

		event2 = new TableEventListener2(this);

		appendBtn.addActionListener(event2);
		deleteBtn.addActionListener(event2);
		printBtn.addActionListener(event2);

		

		
		
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getScroll(), BorderLayout.CENTER);
			jContentPane.add(getInputPanel(), BorderLayout.WEST);
			jContentPane.add(getControlPanel(), BorderLayout.SOUTH);
		}
		return jContentPane;
	}

} // @jve:decl-index=0:visual-constraint="10,10"
